/**
 * 
 */
package com.romotc.qqrobot.webqq.qqInterfaceCatching;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import org.json.JSONException;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.qqrobot.webqq.WebQQConstant;
import com.romotc.scache.RequestSpy;
import com.romotc.scache.WebConnection;

/**
 * 拦截请求
 * @author Administrator
 *
 */
public abstract class QQUrlCatchingInterface {

	/**
	 * 在请求发出之前进行拦截
	 * @param requestSpy
	 * @return 是否继续发出请求
	 */
	public abstract boolean hackRequest(RequestSpy requestSpy);
	
	/**
	 * 在请求返回之后修改响应信息
	 * @param wc
	 * @param rqSpy
	 * @return 是否调用下一个拦截器的modifyResponse方法：false 调用；true 不调用
	 * @throws IOException
	 */
	public abstract boolean modifyResponse(WebConnection wc ,RequestSpy rqSpy) throws IOException;
	
	
	public final QQLogedin getCurQqLogedIn(RequestSpy requestSpy) {
		String curQQ;
		try {
			curQQ = requestSpy.getReqCookiesJson().getString(WebQQConstant.Cookie_ptui_loginuin);
			QQLogedin curLoginQQ = QQLogedin.getCurQqLogedIn(curQQ);
			return curLoginQQ;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
